package com.golxen.framework.common.server.agent.cmd;

import com.golxen.framework.AgentProtocol;
import com.golxen.framework.PBPacket.PBPacket;
import com.golxen.framework.common.server.agent.AgentPlayerMgr;
import com.golxen.framework.common.server.game.cmd.Cmd;
import com.golxen.framework.common.server.game.cmd.Command;
import com.golxen.utils.LogUtil;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = AgentProtocol.A_PLAYER_QUIT, desc = "客户端退出游戏(客户端直发)")
public class PlayerQuitCmd implements Command {

	@Override
	public Command.Tuple execute(ChannelHandlerContext ctx, PBPacket packet) throws Exception {
		long userId = packet.getPlayerId();
		AgentPlayerMgr.removeOnlineDelay(userId, ctx.channel());

		String ip = ctx.channel().remoteAddress().toString();
		LogUtil.COMMON.info("[loginmark] agent logout {} {} {} {}", ctx.channel().id().asShortText(),
				ctx.channel().remoteAddress(), userId, ip);

		return new Tuple(null, null);
	}
}
